home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / variantdemo.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  1.8 KB  |  59 lines

  1. {
  2. GPC demo program. Automatically setting discriminants of variant
  3. records in `New'. (This is a Standard Pascal feature missing in many
  4. popular Pascal compilers.)
  5.  
  6. Copyright (C) 1999-2001 Free Software Foundation, Inc.
  7.  
  8. Author: Frank Heckenbach <frank@pascal.gnu.de>
  9.  
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License as
  12. published by the Free Software Foundation, version 2.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; see the file COPYING. If not, write to
  21. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA.
  23.  
  24. As a special exception, if you incorporate even large parts of the
  25. code of this demo program into another program with substantially
  26. different functionality, this does not cause the other program to
  27. be covered by the GNU General Public License. This exception does
  28. not however invalidate any other reasons why it might be covered
  29. by the GNU General Public License.
  30. }
  31.  
  32. program VariantRecordsDemo;
  33.  
  34. type
  35.   VariantRecord = record
  36.     case Color : (Red, Green, Blue) of
  37.       Red   : (RedFoo   : Integer);
  38.       Green : (GreenBar : Real);
  39.       Blue  : (BlueBaz  : Boolean)
  40.     end;
  41.  
  42. const
  43.   ColorNames : array [Red .. Blue] of String (5) = ('Red', 'Green', 'Blue');
  44.  
  45. var
  46.   v : ^VariantRecord;
  47.  
  48. begin
  49.   New (v, Red);
  50.   Writeln (ColorNames [v^.Color]);
  51.   Dispose (v);
  52.   New (v, Green);
  53.   Writeln (ColorNames [v^.Color]);
  54.   Dispose (v);
  55.   New (v, Blue);
  56.   Writeln (ColorNames [v^.Color]);
  57.   Dispose (v);
  58. end.
  59.